import { defineStore } from 'pinia'
import { getVersion } from "@/api/system/log"
export interface ITemplate {
	name: string
	fileId: string
	component: string
	dicid?: string
}

interface ISystemStore {
	template: ITemplate[]
	templateId: string
	redirect: string
	version: string
	userInfo: Record<string, any>
	info: Record<string, any>
	alarmInfo: Record<string, any>
	project: Record<string, any>
}

export const SystemStore = defineStore({
	id: 'system-store',
	state: (): ISystemStore => ({
		template: [],
		templateId: '',
		redirect: '/home',
		alarmInfo: {},
		userInfo: {
			web_name: window.config.web_name,
		},
		info: {},
		project: {},
		version: ""
	}),
	getters: {
		getAlarmInfo(): Record<string, any> {
			return this.alarmInfo
		},
		getTemplates(): ITemplate[] {
			return this.template
		},
		getTemplateId(): string {
			return this.templateId
		},
		getUserInfo(): any {
			return this.userInfo
		},
		getInfo(): any {
			return this.info
		},
		getRedirect(): any {
			return this.redirect
		},
		getProject(): any {
			return this.project
		},
		getVersion(): any {
			return this.version
		},
	},
	actions: {
		async setVersion() {
			const res = await getVersion()
			this.version = res.data;
			// 
		},
		setTemplate(list: ITemplate[]) {
			this.template = list
		},
		setTemplateId(id: string) {
			this.templateId = id
		},
		setUserInfo(info) {
			this.userInfo = info
		},
		setInfo(info) {
			this.info = info
		},
		setAlarmInfo(info) {
			this.alarmInfo = info
		},
		setRedirect(url) {
			this.redirect = url
		},
		setProject(config) {
			this.project = config
		},
	},
})
